var t = require("../../../@babel/runtime/helpers/objectSpread2"), a = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        customBalance: "",
        balance: "",
        valid_hours: "",
        setting_child_receive: 0,
        showSheet: !1,
        form: {
            number: "",
            amount_total: "",
            title: "",
            redpack_type: 1,
            unit_amount: "",
            child_receive: 0
        },
        actions: [ {
            name: "拼手气红包",
            value: 1
        }, {
            name: "固定金额红包",
            value: 0
        } ],
        fileList: [],
        uploadUrl: "upload.uploadPic"
    },
    onLoad: function(t) {
        var a = wx.getStorageSync("yz_basic_info");
        this.setData({
            customBalance: a.balance.balance ? a.balance.balance : "余额"
        });
    },
    onShow: function() {
        this.reserve();
    },
    reserve: function() {
        var t = this, a = e.getNetAddresss("plugin.redpack-user.frontend.redpack.index");
        e._getNetWork({
            url: a,
            success: function(a) {
                1 === a.data.result ? t.setData({
                    balance: a.data.data.balance,
                    valid_hours: a.data.data.valid_hours,
                    need_password: a.data.data.need_password,
                    setting_child_receive: a.data.data.setting_child_receive
                }) : wx.showToast({
                    title: a.data.msg
                });
            }
        });
    },
    showSheet: function() {
        this.setData({
            showSheet: !0
        });
    },
    closeSheet: function() {
        this.setData({
            showSheet: !1
        });
    },
    inpNumber: function(t) {
        var a = t.detail;
        if (a = a.replace(/[^\d]/g, ""), 0 == this.data.form.redpack_type) {
            var e = (a * this.data.form.unit_amount).toFixed(2);
            this.setData({
                "form.amount_total": e
            });
        }
        this.setData({
            "form.number": a
        });
    },
    inpTotal: function(t) {
        var a = t.detail;
        isNaN(a) || this.setData({
            "form.amount_total": a
        });
    },
    inpUnit: function(t) {
        var a = t.detail;
        if (!isNaN(a)) {
            var e = (a * this.data.form.number).toFixed(2);
            this.setData({
                "form.unit_amount": a,
                "form.amount_total": e
            });
        }
    },
    inpTitle: function(t) {
        var a = t.detail;
        this.setData({
            "form.title": a
        });
    },
    checkGiftType: function(t) {
        var e;
        t.detail.value !== this.data.form.redpack_type && this.setData((a(e = {}, "form.amount_total", ""), 
        a(e, "form.unit_amount", ""), e));
        this.setData(a({}, "form.redpack_type", t.detail.value));
    },
    checkChange: function(t) {
        var e = t.detail ? 1 : 0;
        this.setData(a({}, "form.child_receive", e));
    },
    upLoadImg: function(a) {
        var i = a.detail.file, s = this, o = e.getNetAddresss(this.data.uploadUrl);
        wx.uploadFile({
            url: o,
            filePath: i.url,
            name: "file",
            success: function(a) {
                var e = JSON.parse(a.data), o = s.data.fileList, n = void 0 === o ? [] : o;
                n.push(t(t({}, i), {}, {
                    url: e.data.img_url,
                    status: "done",
                    message: "上传完成"
                })), s.setData({
                    fileList: n
                });
            },
            fail: function(a) {
                var e = [];
                e.push(t(t({}, i), {}, {
                    url: "",
                    status: "failed",
                    message: "上传失败"
                })), s.setData({
                    fileList: e
                });
            }
        });
    },
    deletaLoadImg: function(t) {
        var a = this.data.fileList;
        a[t.detail.index] && a.pop(t.detail.index), this.setData({
            fileList: a
        });
    },
    paramsIsEmpty: function() {
        var t = this.data.form;
        if (!t.number) return wx.showToast({
            title: "红包个数不能为0",
            icon: "none"
        }), !0;
        if (e._isTextEmpty(1 * t.amount_total) || t.amount_total < 0) {
            if (1 == t.redpack_type) return wx.showToast({
                title: "红包总额不能为空或小于0",
                icon: "none"
            }), !0;
            if (0 == t.redpack_type) return wx.showToast({
                title: "单个红包金额不能为空或小于0",
                icon: "none"
            }), !0;
        }
        return !1;
    },
    grantGift: function() {
        if (!this.paramsIsEmpty()) {
            if (this.data.fileList.length > 0 && (this.data.form.thumb = this.data.fileList[0].url), 
            this.data.form.amount_total > 0) {
                var t = Number(this.data.form.amount_total).toFixed(2);
                this.setData({
                    "form.amount_total": t
                });
            }
            e._isTextEmpty(this.data.form.title) && this.setData({
                "form.title": "红包来袭~"
            });
            var a = JSON.stringify(this.data.form), i = JSON.stringify({
                balance: this.data.balance,
                need_password: this.data.need_password
            });
            wx.navigateTo({
                url: "/packageI/personRed/personRedPay/personRedPay?info=".concat(a, "&member=").concat(i)
            });
        }
    }
});